package dk.degofedal.airfoil

import scala.Math.abs;
import scala.Math.pow;
import scala.Math.sin;
import scala.Math.cos;

class Naca00 (xx : Int, r : Option[Double]= None) {
  
  private val a = 0.2969
  private val b = 0.1260
  private val c = 0.3516
  private val d = 0.2843
  private val e = 0.1015
  
  def foil(t : Double) : (Double, Double) = {
    val T : Double = abs(t)
    var y = ( xx.toDouble / 20.0) * (a * pow(T, 0.5) - b * pow(T, 1) - c * pow(T, 2) + d * pow(T, 3) - e * pow(T, 4))
    	    
    if(t < 0){
      y = -y
    }
    	
    if(r isDefined) {
      (abs((r.get + y) * sin((T - 0.0) / r.get)),r.get - (r.get + y) * cos((T - 0.0) / r.get))
    } else {
      (T, y)
    }
  }
}

object Naca00 {
  def apply(t : Int) = new Naca00(t)
  
  def apply(t : Int, R : Int) = new Naca00(t, Some(R))
}
